Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Expand DatabaseDatabase
Expand TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Collapse CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Expand FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Expand LoopingLooping
Expand Error HandlingError Handling
Expand v.IMP Queriesv.IMP Queries
Expand XMLXML
Expand Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

Monitoring Cursor

 
      DECLARE myCursor CURSOR
      LOCAL
      STATIC
      FOR SELECT Name FROM EMP

      DECLARE @Name char(20)

      OPEN myCursor

      FETCH myCursor into @Name

      SELECT  @@CURSOR_ROWS as CursorRows,
              @Name,
              @@FETCH_STATUS AS FetchStatus,
              CURSOR_STATUS('local', 'myCursor') AS CursorStatus

      CLOSE myCursor

      DEALLOCATE myCursor

      
/* ------------------------------ @@Fetch_Status Codes ------------------------------- 0 The Fetch was successful -1 The Fetch Failed -2 The row Fetched is missing -------------------------------- @@CURSOR_ROWS returns the Number of rows in the most recent cursor opened on the connection. @@FETCH_STATUS returns information about the last FETCH command issued. */